<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="户主名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入户主名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="户主名(副)" prop="namee">-->
<!--        <el-input-->
<!--          v-model="queryParams.namee"-->
<!--          placeholder="请输入户主名(副)"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="身份证" prop="idcard">-->
<!--        <el-input-->
<!--          v-model="queryParams.idcard"-->
<!--          placeholder="请输入身份证"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="手机号" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="gender">
        <el-input
          v-model="queryParams.gender"
          placeholder="请输入性别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="户籍地址" prop="address">-->
<!--        <el-input-->
<!--          v-model="queryParams.address"-->
<!--          placeholder="请输入户籍地址"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="工作单位" prop="wordnuit">-->
<!--        <el-input-->
<!--          v-model="queryParams.wordnuit"-->
<!--          placeholder="请输入工作单位"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="现居地址" prop="caddress">-->
<!--        <el-input-->
<!--          v-model="queryParams.caddress"-->
<!--          placeholder="请输入现居地址"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="是否删除(0-未删, 1-已删)" prop="isDeleted">-->
<!--        <el-input-->
<!--          v-model="queryParams.isDeleted"-->
<!--          placeholder="请输入是否删除(0-未删, 1-已删)"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="楼栋id" prop="ldid">-->
<!--        <el-input-->
<!--          v-model="queryParams.ldid"-->
<!--          placeholder="请输入楼栋id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="单元id" prop="dyid">-->
<!--        <el-input-->
<!--          v-model="queryParams.dyid"-->
<!--          placeholder="请输入单元id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="楼层id" prop="lcid">-->
<!--        <el-input-->
<!--          v-model="queryParams.lcid"-->
<!--          placeholder="请输入楼层id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:proprietor:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:proprietor:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:proprietor:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:proprietor:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="proprietorList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="户主名" align="center" prop="name" />
      <el-table-column label="户主名(副)" align="center" prop="namee" />
      <el-table-column label="身份证" align="center" prop="idcard" />
      <el-table-column label="手机号" align="center" prop="phone" />
      <el-table-column label="性别" align="center" prop="gender" >
        <template slot-scope="scope">
          {{scope.row.gender==1?'男':'女'}}
        </template>
      </el-table-column>
      <el-table-column label="户籍地址" align="center" prop="address" />
      <el-table-column label="工作单位" align="center" prop="wordnuit" />
      <el-table-column label="现居地址" align="center" prop="caddress" />
<!--      <el-table-column label="是否删除(0-未删, 1-已删)" align="center" prop="isDeleted" />-->
<!--      <el-table-column label="楼栋id" align="center" prop="ldid" />-->
<!--      <el-table-column label="单元id" align="center" prop="dyid" />-->
<!--      <el-table-column label="楼层id" align="center" prop="lcid" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"d
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:proprietor:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:proprietor:remove']"
          >删除</el-button>
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon=""-->
<!--            @click="handleDetail(scope.row)"-->
<!--            v-hasPermi="['system:proprietor:edit']"-->
<!--          >详情</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改illustriousness.`t_proprietor`对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="户主名" prop="name">
          <el-input v-model="form.name" placeholder="请输入户主名" />
        </el-form-item>
        <el-form-item label="户主名(副)" prop="namee">
          <el-input v-model="form.namee" placeholder="请输入户主名" />
        </el-form-item>
        <el-form-item label="身份证" prop="idcard">
          <el-input v-model="form.idcard" placeholder="请输入身份证" />
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入手机号" />
        </el-form-item>
        <el-form-item label="性别" prop="gender">
          <el-radio v-model="form.gender" :label="1">男</el-radio>
          <el-radio v-model="form.gender" :label="2">女</el-radio>
        </el-form-item>
        <el-form-item label="户籍地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入户籍地址" />
        </el-form-item>
        <el-form-item label="工作单位" prop="wordnuit">
          <el-input v-model="form.wordnuit" placeholder="请输入工作单位" />
        </el-form-item>
        <el-form-item label="现居地址" prop="caddress">
          <el-input v-model="form.caddress" placeholder="请输入现居地址" />
        </el-form-item>
<!--        <el-form-item label="是否删除(0-未删, 1-已删)" prop="isDeleted">-->
<!--          <el-input v-model="form.isDeleted" placeholder="请输入是否删除(0-未删, 1-已删)" />-->
<!--        </el-form-item>-->
        <el-form-item label="楼栋号" prop="ldid">
          <el-select v-model="form.ldid">
            <el-option
              v-for="ld in ldlist"
              :key="ld.ldId"
              :value="ld.ldId"
              :label="ld.ldName"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="单元号" prop="dyid">
          <el-select v-model="form.dyid">
            <el-option
              v-for="dy in dylist"
              :key="dy.dyId"
              :value="dy.dyId"
              :label="dy.dyName"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="单元号" prop="lcid">
          <el-select v-model="form.lcid">
            <el-option
              v-for="lc in lclist"
              :key="lc.lcId"
              :value="lc.lcId"
              :label="lc.lcId"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
<!--    <el-dialog title="更多信息" :visible.sync="open" :close-on-click-modaaxl="false">-->
<!--      <el-table-->
<!--        :data="xqlist"-->
<!--        border-->
<!--        style="width: 100%">-->
<!--        <el-table-column-->
<!--          prop="ldid"-->
<!--          label=""-->
<!--          width="180">-->
<!--        </el-table-column>-->
<!--        <el-table-column-->
<!--          prop="name"-->
<!--          label="姓名"-->
<!--          width="180">-->
<!--        </el-table-column>-->
<!--        <el-table-column-->
<!--          prop="address"-->
<!--          label="地址">-->
<!--        </el-table-column>-->
<!--      </el-table>-->
<!--    </el-dialog>-->
  </div>
</template>

<script>
import {
  listProprietor,
  getProprietor,
  delProprietor,
  addProprietor,
  updateProprietor,
  getldlist, getdylist, getlclist
} from "@/api/system/proprietor";

export default {
  name: "Proprietor",
  data() {
    return {
      ldlist:[],
      dylist:[],
      lclist:[],
      xqlist:[],//详情
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // illustriousness.`t_proprietor`表格数据
      proprietorList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        namee: null,
        idcard: null,
        phone: null,
        gender: null,
        address: null,
        wordnuit: null,
        caddress: null,
        isDeleted: null,
        ldid: null,
        dyid: null,
        lcid: null
      },
      //楼栋查询参数
      queryldlist: {
        ld_id: null,
        ld_name: null,
      },
      //单元查询参数
      querydylist: {
        dy_id:null,
        dy_name:null,
      },
      //单元查询参数
      querylclist: {
        lc_id:null,
        lc_lou:null,
        lc_fang:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: [
          { required: true, message: "户主名不能为空", trigger: "blur" }
        ],
        namee: [
          { required: true, message: "户主名(副)不能为空", trigger: "blur" }
        ],
        idcard: [
          { required: true, message: "身份证不能为空", trigger: "blur" }
        ],
        phone: [
          { required: true, message: "手机号不能为空", trigger: "blur" }
        ],
        gender: [
          { required: true, message: "性别不能为空", trigger: "blur" }
        ],
        address: [
          { required: true, message: "户籍地址不能为空", trigger: "blur" }
        ],
        wordnuit: [
          { required: true, message: "工作单位不能为空", trigger: "blur" }
        ],
        caddress: [
          { required: true, message: "现居地址不能为空", trigger: "blur" }
        ],
        // isDeleted: [
        //   { required: true, message: "是否删除(0-未删, 1-已删)不能为空", trigger: "blur" }
        // ],
      }
    };
  },
  created() {
    this.getList();

  },
  methods: {
    /** 查询illustriousness.`t_proprietor`列表 */
    getList() {
      this.loading = true;
      listProprietor(this.queryParams).then(response => {
        this.proprietorList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        // ldlist:null,
        id: null,
        name: null,
        namee: null,
        idcard: null,
        phone: null,
        gender: null,
        address: null,
        wordnuit: null,
        caddress: null,
        createTime: null,
        updateTime: null,
        // isDeleted: null,
        ldid: null,
        dyid: null,
        lcid: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.getldlist();
      this.getdylist();
      this.getlclist();
      this.reset();
      this.open = true;
      this.title = "添加illustriousness.`t_proprietor`";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getProprietor(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改illustriousness.`t_proprietor`";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateProprietor(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addProprietor(this.form).then(response => {
              console.log(this.form)
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除illustriousness.`t_proprietor`编号为"' + ids + '"的数据项？').then(function() {
        return delProprietor(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/proprietor/export', {
        ...this.queryParams
      }, `proprietor_${new Date().getTime()}.xlsx`)
    },
    //查看详情
    // handleDetail(row){
    //   const id = row.id
    //   this.open = true;
    //   getProprietor(id).then(res=>{
    //     console.log(res)
    //     this.xqlist=res
    //   })
    // },
    //查询所有楼栋
    getldlist(){
      getldlist(this.queryldlist).then(res=>{
        this.ldlist=res.rows  //
      })
    },
    //查询所有单元
    getdylist(){
      getdylist(this.querydylist).then(res=>{
        console.log(res)
        this.dylist=res.rows
      })
    },
  //  查询所有层
    getlclist(){
      getlclist(this.querylclist).then(res=>{
        this.lclist=res.rows
      })
    }
  }
};
</script>
